import { useState, useEffect } from 'react'
import axios from 'axios'

const useAuth = () => {
    const isLogin = localStorage.getItem("token")? true: false
    return {
        isLogin
    }
}



// 自定义Hooks   use开头的函数, 可以使用react中内置hooks
const useInit = (url: string) => {
    const [list, setList] = useState([])

    const search = (val: string | number) => {
        axios.get(url, {
            params: {
                val
            }
        }).then(res => {
            setList(res.data.data)
        })
    }
    useEffect(() => {
        axios.get(url).then(res => {
            setList(res.data.data)
        })
    }, [])

    return [list, search]
}

export {
    useAuth,
    useInit
}